home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / tst0831.zip / TSTIC.C < prev    next >
Text File  |  1990-07-16  |  7KB  |  235 lines

  1. /********************************************************************
  2.         PopTEST  (c) Copyright 1989 by MSI
  3.              Author - Ratko V. Tomic
  4. *********************************************************************/
  5.  
  6. #include "cr.h"
  7. #include "sio.h"
  8.  
  9. #ifdef PDK1
  10. #include "lm.h"
  11. #include "sr.h"
  12. #else
  13. #define _even_heap() _heap=(char*)(((word)_heap+1)&0xFFFE)
  14. #endif
  15.  
  16. #include "spawn.h"
  17.  
  18. #define MK_FP(seg,ofs)    ((void far *)(((dword)(seg)<<16)|(word)(ofs)))
  19.  
  20. /** STARTUP DATA are in XID.C  (discarded in resident mode) **/
  21.  
  22. extern char loaded_msg[],hello_msg[]; /* Startup messages */
  23. extern char hello_atr[],hello_atr1[];
  24. extern char unloading[],not_loaded[],no_unl[];
  25.  
  26. extern word init_data_end;    /* Marks end of init-data */
  27. extern word parent_code;    /* Code segment if already loaded */
  28.  
  29. #define UNL_KEY (M_LC|M_LS|0x16)    /* Ctl-Shift-U */
  30.  
  31. /********** USED FOR SPAWN ******************************************/
  32. extern char img_file[];        /* Disposable memory swap file name */
  33. extern int img_hndl;        /* Permanent data file/lim handle */
  34. extern word lim_seg;        /* Used only if LIM available */
  35. extern dword lfpos;        /* LIM or file position for graph image*/
  36. extern word MinP,MaxP;        /* Minimum/Maximum paragraphs to use */
  37. extern char prog[],cmd_ln[];    /* Fill in command line and program */
  38. extern char *shell_ptr;        /* Default SHELL */
  39. extern word *scr_buf;        /* Screen buffer */
  40. extern char *tmp_buf;        /* Temporary buffer */
  41. extern word cmd_env;        /* Environment passed to spawn() */
  42. extern char run_it;        /* Set to NZ if no questions asked on F11 */
  43. /*********************************************************************/
  44.  
  45. /** RESIDENT CODE STACK SPACE **/
  46.  
  47. #define STK_SZ (128)      /* Size in words */
  48. word res_stack[STK_SZ+1]; /* Allow allways extra word ! */
  49.  
  50. extern isr();        /* Interrupt service in X.C */
  51. extern word hk_list[];  /* This is in X.C for use by isr() function */
  52.  
  53.  
  54. /** Display Signon screen **/
  55.  
  56. signon()
  57. {
  58.   int x0,y0,x1,y1;
  59.   char *a=hello_atr;
  60.  
  61.    if (vid_mode==7)
  62.     a=hello_atr1;
  63.    x0=crs_x=12; y0=crs_y=3;
  64.    vid_atr=7; fil_scr('░');
  65.      dspf(hello_msg,a);
  66.    x1=crs_x; y1=crs_y+1;
  67.    vid_atr=7;
  68.    crs_y=y0+1; dsp_ver(0x20,y1-y0);
  69.    crs_x++; crs_y=y0+1; dsp_ver(0x20,y1-y0);
  70.    crs_x=x0+3;crs_y=y1; dsp_hor(0x20,x1-x0-1);
  71.    crs_x=0; crs_y=24;
  72.    vid_atr=7; clr_eol();
  73.    crs_y--; mv_crs();
  74. }
  75.  
  76. /** PARSE COMMAND LINE **/
  77.  
  78. char *cpy_tok(char *src,char *dest,int max)
  79. { register char *s=src,*d=dest;
  80.    while (*s>0x20 && --max>=0) *d++=*s++;
  81.    return(s);
  82. }
  83.  
  84. parse_cmd_ln()
  85. { register char *s=cmd_line;
  86.   word n;
  87.   char *endl;
  88.      endl=s+str_len(s);
  89.      while (*s && s<endl && s>=cmd_ln )
  90.     {
  91.     if (*s++!='/') continue;
  92.     if (!*s) continue;
  93.     n=(*s++ | 0x20);
  94.     switch (n) {
  95.       case 'm':    s=dec2w(s,&n);
  96.             if (n>640 || n<16 ) break;
  97.             MaxP=MinP=n*(1024/16)+1;
  98.             break;
  99.       case 'q':    run_it|=0x80;
  100.       case 'g':     run_it|=1;
  101.             break;
  102.       case 'p':    ;
  103.       case 'f':    s=cpy_tok(s,prog,64); break;
  104.       case 'c':    strncpy(cmd_ln+2,s,64);
  105.             *(word*)(cmd_ln+str_len(cmd_ln))=0xd;
  106.             return(0);
  107.       case 'u':    return(n);
  108.       }
  109.     }
  110.      return(0);
  111. }
  112.  
  113.  
  114. extern char cmd_pref[],dflt_shell[];
  115.  
  116. get_comspec()
  117. { char far *e;
  118.   register char *s;
  119.   register int n;
  120.   char *sh=dflt_shell;
  121.      n=str_len(cmd_pref);
  122.      e=MK_FP(_env,0);
  123.      do {
  124.     s=_heap;
  125.     do *s=*e++; while (*s++);
  126.     s=_heap;
  127.     if (mem_cmp(s,cmd_pref,n)==n)
  128.       {
  129.       sh=s+n; break;
  130.       }
  131.     }
  132.      while (*e);
  133.      s=shell_ptr=_heap;
  134.      _heap+=str_cp(sh,s)+1;
  135. }
  136.  
  137. /******* INITIALIZATION *******/
  138.  
  139.  
  140. main()
  141. { int unl_req;
  142.   int h2;        /* Second LIM handle */
  143.  
  144.   signon();
  145.   unl_req= parse_cmd_ln();    /* Extract memory size & default application */
  146.  
  147.   if (second_load())         /* Check if program already loaded */
  148.     {
  149.     if (unl_req)
  150.        {
  151.        if (!remove_tsr())
  152.         {
  153.         dspf(no_unl);    /* Can't unload - other TSR took our */
  154.         return(1);    /* interrupt vector.             */
  155.         }
  156. #ifdef PDK1
  157.        h2=*(int far*)MK_FP(parent_code,8); /* Get other LIM handle */
  158.        if (h2!=-1) lim_dealloc(h2);           /* Release it if LIM used */
  159. #endif
  160.        fdelete(img_file);    /* Delete swap file (if found) */
  161.        dspf(unloading);
  162.        }
  163.     else dspf(loaded_msg);    /* If so, display error message  */
  164.     return(1);        /* Exit to DOS with errorlevel 1 */
  165.     }
  166.    else if (unl_req) 
  167.     {
  168.     dspf(not_loaded);
  169.     return(1);
  170.     }
  171.  
  172. /******* ENABLE RESIDENT OPERATION *********************************/
  173.  
  174.   idata_end=&init_data_end;    /* This enables init data disposal. */
  175.   icode_beg=signon;        /* This enables init code disposal. */
  176.  
  177.   stay_resident(res_stack,STK_SZ*2);    /* Define TSR stack */
  178.   install_hk(hk_list,isr,STK_SZ*2,3);    /* Enable HOT-KEY services */
  179.  
  180. /******** INITIALIZE SWAP FILE/LIM FOR SPAWN **************************/
  181.  
  182.     get_comspec();    /* Extract COMMAND.COM path from Environment */
  183.     tmp_buf=_heap;
  184.     _heap += mouse_size>128 ? mouse_size: 128; /* Reserva Mouse-save area */
  185.  
  186.     cmd_env=get_master_env();        /* Get ENVIRONMENT TO USE */
  187.     if (!cmd_env) keep_env();        /* Use ours if no master_env */
  188.  
  189.  
  190. #ifdef PDK1    /* Acquire LIM pages (requires PDK-1: K1.LIB) */
  191.  
  192. { word min_pages,max_pages,nfree,mp;
  193.  
  194.     if (!lim_present()) goto FileOnly; /* Check if LIM board present */
  195.     move_to_lim(1,1,MOVE_BOTH);        /* Load TSR into LIM as well */
  196.     mp=(mouse_size+0xf)>>4;        /* Space to save mouse state */
  197.     min_pages = 17+((MinP+1)+mp+0x3FF)/0x400;    /* Minimum pages necessary */
  198.     max_pages = 17+((MaxP+1)+mp+0x3FF)/0x400;   /* Maximum pages necessary */
  199.     nfree=lim_nfree();            /* Get # of free pages */
  200.     
  201.     if (lim_error) goto FileOnly;
  202.     if (nfree<min_pages) goto FileOnly;   /* Don't use LIM if too small */
  203.     if (nfree<max_pages) max_pages=nfree; /* Else alloc max possible */
  204.     img_hndl=lim_alloc((int)max_pages);    /* Allocate pages */
  205.     if (lim_error) goto FileOnly;
  206.     lim_seg=lim_window();        /* Enable LIM saving of image */
  207.     lfpos=max_pages-17;
  208.     h2=img_hndl;            /* Used to remove_tsr() */
  209.     if (!lim_error) goto LimOnly;
  210.     lim_dealloc(img_hndl);        /* Release LIM on error */
  211. }
  212. #else    /**** If no PDK-1 reserve 4K for screen save ****/
  213.  
  214.     _even_heap();
  215.     scr_buf=(word*)_heap;
  216.     _heap+=80*25*2;
  217.  
  218. #endif
  219.  
  220. FileOnly:
  221.   h2=-1;            /* Value -1 is used for file swapping */
  222.   lim_seg=0;            /* Disable LIM use */
  223.   img_hndl=fcreate(img_file,0);    /* Create application mem. swap file */
  224.   if (io_error) exit(1);    /* Don't go TSR if bad image file    */
  225.   lfpos=(((dword)MaxP+1)<<4)+mouse_size;/* Init file pos for graphics image */
  226. LimOnly:
  227.  
  228.   *(int far*)MK_FP(_ccode,8)=h2; /* Save so it can be released later */
  229.                  /* config block ptr in R0.ASM reused */
  230. /*********************************************************************/
  231.   
  232.   return(0);                /* Exit code 0=Ok exit */
  233.  
  234. }
  235.